package com.loveto.common;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.loveto.model.TournamentInfo;
import com.loveto.service.R;

public class TourlistAdapter extends ArrayAdapter<TournamentInfo> {

	private Context mContext;
	private int mResourceMan;
	private int mResourceWoman;
	private List<TournamentInfo> mList;
	private LayoutInflater mInflater;

	/**
	 * @param context
	 * @param layoutResource
	 * @param objects
	 */
	public TourlistAdapter(Context context, int layoutResourceMan, int layoutResourceWoman, List<TournamentInfo> objects) {
		super(context, layoutResourceMan, layoutResourceWoman, objects);
		this.mContext = context;
		this.mResourceMan = layoutResourceMan;
		this.mResourceWoman = layoutResourceWoman;
		this.mList = objects;
		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TournamentInfo tourinfo = mList.get(position);

		if (convertView == null) {
			if("M".equals(tourinfo.getGender())) {
				convertView = mInflater.inflate(mResourceMan, null);
			} else if("F".equals(tourinfo.getGender())) {
				convertView = mInflater.inflate(mResourceWoman, null);
			} else {
				Log.d("tag", "성별값이 잘못되었습니다.");
			}
		}

		if (tourinfo != null) {
			TextView tourTitle = (TextView) convertView.findViewById(R.id.tourinfo_title_text);
			// 스크린네임 세팅
			tourTitle.setText(tourinfo.getTournamentTitle());
		}

		return convertView;
	}
}
